<?php

namespace apiend\modules\user\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\user\models\FollowForm;
use apiend\modules\user\models\FollowTeacherSearch;
use apiend\modules\user\models\FollowSchoolSearch;

/**
 * 用户群聊相关接口
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class GroupController extends Controller {

    public $modelClass = 'apiend\modules\user\models\GroupSearch';

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * @inheritdoc
     */
    protected function verbs() {
        return [
            'index' => ['GET'],
            'remark' => ['POST'],
        ];
    }

    /**
     * 关注的教师列表
     * @inheritdoc
     */
    public function actionIndex() {
        /* @var $modelClass \apiend\modules\user\models\GroupSearch */
        $modelClass = new $this->modelClass;
        return $modelClass->search($this->token->user_id);
    }

    /**
     * 加入群聊
     */
    public function actionJoin() {
        $model = new GroupJoinForm();
        if (!$model->load(Yii::$app->request->post(), '')) {
            return $model->dumpError('参数校验失败');
        }
        $model->user_id = $this->token->user_id;
        return $model->save();
    }

}
